import { Component, OnInit } from '@angular/core';
import { ApiSystemService } from '../../../api/system/api-system.service';
import { FormGroup, FormControl } from '@angular/forms';
import { FormBuilder, Validators } from '@angular/forms';

@Component({
  selector: 'sda-settings',
  templateUrl: './settings.component.html',
  // styleUrls: ['./settings.component.scss']
})
export class SettingsComponent implements OnInit {

  name = new FormControl('aaa');

  tab_list: string[] = [];
  // 当前 category
  current_category: string = '';

  constructor(
    private apiService: ApiSystemService,
    private fb: FormBuilder,
  ) { }


  powers = ['Really Smart', 'Supser Flexible',
    'Super Hot'];

  profileForm = new FormGroup({
    firstName: new FormControl('martin'),
    lastName: new FormControl('wu'),
    address: new FormGroup({
      street: new FormControl('street'),
      city: new FormControl('city'),
    }),
  });


  //fb 
  profileForm2 = this.fb.group({
    firstName: ['22222', Validators.required],
    lastName: [''],
    address: this.fb.group({
      street: [''],
      city: [''],
      zip: ['']
    })
  
  })


  onSubmit() {
    console.log('提交了')
    console.log(this.profileForm2.value)
  }


  updateName() {
    this.name.setValue('Wubuze');
  }

  updateProfile() {
    this.profileForm.patchValue({
      firstName: 'Nancy',
      address: {
        street: '123 Drew Street'
      }
    });
  }

  

  ngOnInit() {
    this.fetchSystemCategoryList();
  }

  /**
   * 获取system item 列表
   *
   * @memberof SettingsComponent
   */
  fetchSystemCategoryList() {
    this.apiService
      .getSystemList()
      .subscribe(res => {
        this.tab_list = res.dat;
        // debugger;
      });
  }

  /**
   * tab 切换事件
   *
   * @param {number} e
   * @memberof SettingsComponent
   */
  onTabChange(e: number) {
    this.current_category = this.tab_list[e];
  }

}
